<%@ page language="java" import="java.util.*,com.inspur.ch8.Person" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'test3.jsp' starting page</title>
  </head>
  
  <body>
   
    <!-- 2、利用foreach来遍历输出集合信息 -->
    <%
     String names[] = new String[3];
     names[0]="zhangsan";
     names[1]="lisi";
     names[2]="wangwu";
     pageContext.setAttribute("names", names);
     %>
     <%
     Map map = new HashMap();
     map.put("zhangsan1","200.0");
     map.put("lisi","2000.0");
     request.setAttribute("map",map);
      %>
     <c:forEach items="${map}" var="entry"></c:forEach>
     <!-- 遍历输出人的信息 -->
     <%
      ArrayList<Person> personList = new ArrayList<Person>();
      Person p1 = new Person();
      p1.setName("zhangsan1");
      p1.setAge(20);
      p1.setSex("男");
      Person p2 = new Person();
      p2.setName("zhangsan2");
      p2.setAge(21);
      p2.setSex("男");
      Person p3 = new Person();
      p3.setName("zhangsan3");
      p3.setAge(22);
      p3.setSex("男");
      personList.add(p1);
      personList.add(p2);
      personList.add(p3);
      %>
      <c:set var="personList" value="<%=personList%>" scope="session"></c:set>
      <!-- 把上面的表格信息进行美化，完成隔行变色的效果 -->
      <table border="1px" width="100%">
      <c:forEach var="p" items="${personList}" varStatus="s">
        <c:if test="${s.count%2==0 }">
         <tr>
        </c:if>
        <c:if test="${s.count%2!=0}">
         <tr>
        </c:if>
          <td><c:out value="${s.index}"></c:out></td>
          <td><c:out value="${p.name}"></c:out></td>
          <td><c:out value="${p.age}"></c:out></td>
          <td><c:out value="${p.sex}"></c:out></td>
        </tr>
      </c:forEach>
      </table>
  </body>
</html>
